﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace JTG.CheckInMachine.UserControl
{
    public partial class PwdKeyboard : System.Windows.Forms.UserControl
    {
        public EventHandler CloseEvent; //清除
        int _closeTime = 3;

        public PwdKeyboard()
        {
            InitializeComponent();
        }

        #region 关闭窗口密码输入框

        private void btn_ClearPwd_Click(object sender, EventArgs e)
        {
            txt_pwd.Text = "";
        }

        internal void CloseTimeReset()
        {
            _closeTime = 3;
            lab_CloseTips.Text = $"{_closeTime}秒后关闭";
            timer1.Enabled = true;
        }

        private void btn_DelPwd_Click(object sender, EventArgs e)
        {
            _closeTime = 3;
            if (btn_DelPwd.Text == "关闭")
            {
                Hide();
                timer1.Enabled = false;
            }

            if (txt_pwd.Text.Length > 0)
                txt_pwd.Text = txt_pwd.Text.Substring(0, txt_pwd.Text.Length - 1);

            if (txt_pwd.Text.Length == 0)
                btn_DelPwd.Text = "关闭";
        }

        private void btn_NumClick(object sender, EventArgs e)
        {
            _closeTime = 3;
            txt_pwd.Text += ((Button)sender).Text;
            btn_DelPwd.Text = "删除";

            if (txt_pwd.Text == "666666")
                CloseEvent?.Invoke(sender, e);
        }

        #endregion

        private void timer1_Tick(object sender, EventArgs e)
        {
            lab_CloseTips.Text = $"{_closeTime}秒后关闭";
            if (_closeTime <= 0)
            {
                Hide();
                timer1.Enabled = false;
            }

            _closeTime--;
        }
    }
}
